'use strict';

module.exports = app => {
    const { Sequelize, model } = app

    const Model = model.define('client', {
        id:{
            type: Sequelize.STRING.BINARY,
            defaultValue: Sequelize.UUIDV1,
            primaryKey: true
        },
        userName:{
            type: Sequelize.STRING(30),
            //allowNull: false,
        },
        mobile:{
            type: Sequelize.STRING(20),
            //allowNull: false,
        },
        telephone:{
            type: Sequelize.STRING(20),
        },
        address:{
            type: Sequelize.STRING(200),
        },
        carNum:{
            type: Sequelize.STRING(10),
            allowNull: false,
        },
        carType:{
            type: Sequelize.STRING(10),
            allowNull: false,
        },
        oilType:{
            type: Sequelize.INTEGER(1),
            defaultValue: 0,
        },
        carMac:{
            type: Sequelize.STRING(20),
        },
        carEng:{
            type: Sequelize.STRING(20),
        },
        checkDate:{
            type: Sequelize.DATE,
        },
        openId:{
            type: Sequelize.STRING(50),
        },
    }, {
        freezeTableName: true,
        tableName: 'tb_client',
        timestamps: true,
        paranoid: true,
        indexes: [
            {
                unique: true,
                fields: ['corpId', 'carNum']
            },
        ]
    })

    Model.associate = function() {
        model.Client.belongsTo(model.Corp)
        model.Client.belongsTo(model.Agent)
        model.Corp.hasMany(model.Client)
        model.Agent.hasMany(model.Client)
    }

    return Model
}